﻿using System.IO;

namespace Jailu.AutoUpdater
{
    public static class DirectoryExtension
    {
        public static void CopyTo(this DirectoryInfo source, DirectoryInfo destination, bool copySubDirectories)
        {
            if (!destination.Exists)
            {
                destination.Create();
            }

            foreach (FileInfo file in source.GetFiles())
            {
                file.CopyTo(Path.Combine(destination.FullName, file.Name), true);
            }

            if (copySubDirectories)
            {
                foreach (DirectoryInfo directory in source.GetDirectories())
                {
                    var destinationDir = Path.Combine(destination.FullName, directory.Name);
                    directory.CopyTo(new DirectoryInfo(destinationDir), copySubDirectories);
                }
            }
        }
    }
}
